package com.ssyc.student.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ssyc.common.adapter.CommonAdapter;
import com.ssyc.common.adapter.ViewHolder;
import com.ssyc.student.R;
import com.ssyc.student.bean.StShowAnserInfo;

import java.util.List;

/**
 * 学生端--词汇预习--展示选择答案的适配器
 * Created by Administrator on 2018/5/10 0010.
 */

public class StShowAnswerLvAdapter extends CommonAdapter<StShowAnserInfo> {

    private Context context;

    public StShowAnswerLvAdapter(Context context, List<StShowAnserInfo> datas, int layoutId) {
        super(context, datas, layoutId);
        this.context = context;
    }

    @Override
    public void convert(ViewHolder holder, StShowAnserInfo stAnswerInfo) {
        //序列号
        TextView tvNum = holder.getView(R.id.tv_answer_num);
        tvNum.setText(stAnswerInfo.getId());
        //你的作答
        TextView tvChooseAnswer = holder.getView(R.id.tv_choose_answer);
        if (TextUtils.isEmpty(stAnswerInfo.getChooseNum())) {
            tvChooseAnswer.setVisibility(View.INVISIBLE);
        } else {
            tvChooseAnswer.setVisibility(View.VISIBLE);
            tvChooseAnswer.setText(stAnswerInfo.getChooseNum());
        }

        //正确答案的线性布局
        LinearLayout llRightAnswer = holder.getView(R.id.ll_right_answer);

        //正确答案的选项
        TextView tvRightAnswer = holder.getView(R.id.tv_right_answer);

        //如果选择的答案序列号跟提供的答案的序列号一致,证明选择正确,否则选择错误
        if (TextUtils.isEmpty(stAnswerInfo.getChooseNum())) {
            //没选择答案时不显示
            llRightAnswer.setVisibility(View.GONE);
        } else {
            //选择答案以后判断选择的答案和正确答案的序号是否一致
            if (stAnswerInfo.getChooseNum().equals(stAnswerInfo.getRightNum())) {
                llRightAnswer.setVisibility(View.GONE);
                tvChooseAnswer.setBackgroundResource(R.drawable.st_tv_right_answer);
            } else {
                llRightAnswer.setVisibility(View.VISIBLE);
                tvChooseAnswer.setBackgroundResource(R.drawable.st_tv_error_answer);
                tvRightAnswer.setText(stAnswerInfo.getRightNum());
            }
        }

    }
}
